package com.wzy.portfolio.handlers;

import com.wzy.portfolio.service.FundService;
import com.wzy.portfolio.utils.DateStyle;
import com.wzy.portfolio.utils.DateTool;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class FundJob {

    @Autowired
    FundService fundService;

    /**
     * 获取待监控的基金详情
     * @return
     */
    @XxlJob("fundZdfDetails")
    public ReturnT<String> fundZdfDetails() {
        log.info("--->基金实时涨跌幅入库<---");
        fundService.fundZdfDetails();
        return ReturnT.SUCCESS;
    }

    @XxlJob("fundHistory")
    public ReturnT<String> fundHistory() {
        log.info("--->基金历史数据入库<---");
        String edate = DateTool.DateToString(new Date(), DateStyle.YYYY_MM_DD);
        String sdate = DateTool.addDay(edate,-10);
        fundService.fundHistory(sdate,edate);
        return ReturnT.SUCCESS;
    }

}
